home *** CD-ROM | disk | FTP | other *** search
- #include "AppInterface.h"
- #include "ColorPicker.h"
- #include "GestaltEqu.h"
-
- #define kPickerMenuID 131
- #define iModalPicker 1
- #define iModelessPicker 2
- #define iAppPicker 3
- #define iPickerPicker 4
-
-
- /* The one shell global we need */
- extern MenuHandle gShellMenuHandles[];
-
- ////////////////
- // Globals
-
- WindowRecord gWStore;
- MenuHandle gPickerMenuHandle = nil;
-
- extern RGBColor myRGBColor;
- extern picker myPicker; // Global picker reference.
- extern WindowPtr myDocWindow;
- extern DialogPtr myDialog;
-
- /* A chance to pre-handle an event */
- Boolean AppDoEvent(EventRecord *event)
- {
- Boolean handled = false;
-
- Boolean SampleDoEvent(EventRecord *event);
-
- handled = SampleDoEvent(event);
- return handled;
- }
-
- /* Called by the Shell at startup time */
- Boolean AppInit(void) /* returns false if initialization fails */
- {
- Rect tempRect = {0, 0, 64, 64};
- long gestaltResult;
-
- // Beep if Color picker not installed
- if(Gestalt(gestaltColorPicker, &gestaltResult) != noErr)
- {
- SysBeep(10);
- return false;
- }
-
- OffsetRect(&tempRect, 30, GetMBarHeight() + 40);
- myDocWindow = NewCWindow(&gWStore, &tempRect, "\pColor", true,
- documentProc, (WindowPtr)(-1), false, 0L);
-
- /* Set up picker menu */
- gPickerMenuHandle = GetMenu(kPickerMenuID);
- if(gPickerMenuHandle == nil)
- {
- SysBeep(10);
- return false;
- }
- (*gPickerMenuHandle)->menuID = kPickerMenuID;
- InsertMenu(gPickerMenuHandle, 0);
-
- /* Update the menu bar */
- DrawMenuBar();
- return true;
- }
-
- /* Called when the shell receives an Activate event. */
- void AppActivate(WindowPtr wind, Boolean activate)
- {
- }
-
- /* Called when a window needs updating. BeginUpdate() has already been called, and the
- port is set to the appropriate window */
- void AppUpdate(EventRecord *event)
- {
- void DoTheUpdate(WindowPtr aWindow);
-
- if((WindowPtr) event->message == myDocWindow)
- {
- RGBForeColor(&myRGBColor);
- PaintRect(&myDocWindow->portRect);
- }
- else
- DrawDialog((WindowPtr) event->message);
- }
-
- /* Called when the shell recieves a null event. */
- void AppIdle(EventRecord *Event)
- {
- }
-
- /* Called when there is a click in the content of a window. The port is already set to
- the window, and thePt is in local coords. */
- void AppClick(Point thePt, WindowPtr whichWindptr, Boolean doubleClick)
- {
- }
-
- /* Called when there is a click in the grow region. */
- void AppGrowWindow(WindowPtr wind, Point where, Rect *desk)
- {
- }
-
- /* Called when the user clicks in the zoom box of a window. */
- void AppZoomWindow(WindowPtr wind, short zoomDir)
- {
- }
-
- /* Called when there is a click in the menu bar, before the menu is shown. This is
- the app's opportunity to enable and disable menu items. */
- void AppAdjustMenus()
- {
- }
-
- /* called when a menu other than Apple, File, or Edit is used. */
- void AppMenu(short id, short item)
- {
- void PickAColor(void);
- OSErr BuildModelessSysDialog(void);
- OSErr BuildAppDialog(void);
- OSErr BuildPickerDialog(void);
-
- OSErr err = noErr;
-
- if(id != kPickerMenuID)
- return;
-
- // Modal is a special case
- if(item == iModalPicker)
- {
- PickAColor();
- return;
- }
-
- switch(item)
- {
- case iModelessPicker:
- err = BuildModelessSysDialog();
- break;
-
- case iAppPicker:
- err = BuildAppDialog();
- break;
-
- case iPickerPicker:
- err = BuildPickerDialog();
- break;
-
- default:
- break;
- }
-
- // If no error, set picker up and show it, disabling the picker menu
- if(err == noErr && myPicker != nil)
- {
- PMColor myPMColor;
-
- myPMColor.color.rgb = myRGBColor;
- myPMColor.profile = 0L;
-
- SetPickerColor(myPicker, kOriginalColor, &myPMColor);
- SetPickerColor(myPicker, kNewColor, &myPMColor);
- SetPickerPrompt(myPicker, "\pModeless Picker");
- SetPickerVisibility(myPicker, true);
- if(item == iAppPicker && myDialog != nil)
- ShowWindow(myDialog);
-
- // Fix menus
- HiliteMenu(0);
- DisableItem(gPickerMenuHandle, 0);
- DrawMenuBar();
- }
- else
- SysBeep(10);
- }
-
- /* Called when the user selects "New" from the File menu. A no-op right now */
- void AppNew(void)
- {
- }
-
- /* Called when the user selects "Open" from the File menu. */
- void AppOpen(void)
- {
- }
-
-
- /* Called when the user selects "Close" from the File menu or clicks the close box
- of a window. */
- Boolean AppClose(void)
- {
- /* returns false if the user cancels the save */
-
- // Must be the app dialog, since that's the only thing with a close box
- void CloseAppPicker(void);
-
- CloseAppPicker();
- EnableItem(gPickerMenuHandle, 0);
- DrawMenuBar();
-
- return true;
- }
-
- /* Called when the user selects "Save" from the File menu. */
- Boolean AppSave(void)
- {
- /* returns false if the user cancels the save */
- return true;
- }
-
- /* Called when the user selects "Save As..." from the File menu. */
- Boolean AppSaveAs(void)
- {
- /* returns false if the user cancels the save */
- return true;
- }
-
- /* Called when the user selects "Page Setup..." from the File menu. */
- void AppPageSetup(void)
- {
- }
-
- /* Called when the user selects "Print..." from the File menu. */
- void AppPrint(void)
- {
- }
-
- /* Called when the user selects "Undo" from the Edit menu. */
- void AppUndo(void)
- {
- }
-
- /* Called when the user selects "Cut" from the Edit menu. */
- void AppCut(void)
- {
- }
-
- /* Called when the user selects "Copy" from the Edit menu. */
- OSErr AppCopy(void)
- {
- return noErr;
- }
-
- /* Called when the user selects "Paste" from the Edit menu. */
- void AppPaste(void)
- {
- }
-
- /* Called when the user selects "Clear" from the Edit menu. */
- void AppClear(void)
- {
- }
-
- /* Called when the user chooses "Quit" from the File menu. If the user cancels
- the save it returns false, otherwise it returns true and the shell quits */
- Boolean AppQuit(void)
- {
- /* returns false if the user cancels the save at any point */
- return true;
- }
-
- /* Called when the shell is about to quit, just deallocates memory. */
- void AppCleanUp(void)
- {
- if(myDocWindow != nil)
- CloseWindow(myDocWindow);
- }
-
-
-